/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import BO.Controller;
import BO.Postit;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Ymmot
 */
public class DisplayUserBean {

    private String id;
    private String username;
    private String address;
    private String zipcode;
    private String city;
    private String country;
    private List<Postit> postits;
    private Controller controller;
    
    /** Creates a new instance of DisplayUserBean */
    public DisplayUserBean() {
        controller = new Controller();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
        if(id != null){
            if(id.matches("[0-9]+")){
                updateBean(Integer.parseInt(id));
            }
        }
    }
    
    private void updateBean(int id){
        Controller c = new Controller();
        UserView u = c.getUserById(id);
        username = u.getUsername();
        address = u.getAddress();
        zipcode = u.getZipcode();
        city = u.getCity();
        country = u.getCountry();
        // TODO: Change to something vettigt. postits = new ArrayList<Postit>(u.getPostitList());
        // System.out.println("Postits size: " + postits.size());
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public List<Postit> getPostits() {
        postits = controller.getLatestPostitsByUserId(Integer.parseInt(getId()));
        return postits;
    }

    public void setPostits(List<Postit> postits) {
        this.postits = postits;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }
    
    
}
